cmake_minimum_required(VERSION 3.10)

set(PROJECT_NAME OKAI-Isla)
set(PROJECT_VERSION "0.1")

project(${PROJECT_NAME} VERSION ${PROJECT_VERSION} LANGUAGES NONE)


if(NOT CMAKE_SYSTEM_NAME STREQUAL "Linux")
    message(FATAL_ERROR "Only Linux is supported")
endif()


# 设置Godot可执行文件路径（使用完整路径）
set(GODOT_EXECUTABLE godot CACHE STRING "Path to Godot executable")

# 判断处理器架构riscv64或x86_64
if(CMAKE_SYSTEM_PROCESSOR STREQUAL "riscv64")
    set(EXPORT_PLATFORM "openKylin_rv64" CACHE STRING "Target platform for export")
elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64")
    set(EXPORT_PLATFORM "openKylin_x86" CACHE STRING "Target platform for export")
else()
    message(FATAL_ERROR "Unsupported architecture: ${CMAKE_SYSTEM_PROCESSOR}")
endif()


set(EXPORT_OUTPUT ${CMAKE_SOURCE_DIR}/build/${EXPORT_PLATFORM} CACHE PATH "Output path for exported binary")

# 添加自定义导出命令
add_custom_target(export
    COMMAND ${CMAKE_COMMAND} -E make_directory "${EXPORT_OUTPUT}"
    COMMAND "${GODOT_EXECUTABLE}"
    --path "${CMAKE_SOURCE_DIR}"
    --export-release "${EXPORT_PLATFORM}"
    "${EXPORT_OUTPUT}/${PROJECT_NAME}"
    --headless
    COMMENT "Exporting Godot project for ${EXPORT_PLATFORM} to ${EXPORT_OUTPUT}"
)

